package com.ljpz.web.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ljpz.common.service.ApiService;
import com.ljpz.sso.query.api.UserQueryService;
import com.ljpz.sso.query.bean.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.net.URISyntaxException;

/**
 * Created by liujunchen on 2016/12/23.
 */
@Service
public class UserService {
//    @Autowired
//    private ApiService apiService  ;
//    private  static  final ObjectMapper  MAPPER = new ObjectMapper()  ;
    @Value("${LJPZ_SSO_URL}")
    public  String  LJPZ_SSO_URL ;
    @Autowired
     private UserQueryService userQueryService ;
    /**
     * 根据token查询用户信息
     *
     * @param token
     * @return
     */
  /*  public User queryByToken(String token){
        try {
            String url=LJPZ_SSO_URL+"/service/user/"+token ;
            String jsonData=this.apiService.doGet(url) ;
            if (StringUtils.isNotEmpty(jsonData)){
                return  MAPPER.readValue(jsonData,User.class)   ;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  null ;
    }*/

    public User queryByToken(String token){

        try {
            return this.userQueryService.queryUserByToken(token) ;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
